from PIL import Image, ImageDraw, ImageFont

text = "Hello, World!"
position = (50, 50)
font_path = "ARIAL.TTF"
font_size = 40
font = ImageFont.truetype(font_path, size=font_size)
color = (255, 0, 0, 255)

image = Image.open("test.png").convert("RGBA")

layer = Image.new("RGBA", image.size, (255, 255, 255, 0))
draw = ImageDraw.Draw(layer)
draw.text(position, text, font=font, fill=color)

result = Image.alpha_composite(image, layer)
result.save("result.png")